package cn.e3.search.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
/*
 * 全局异常处理
 */
public class GlobalExceptionReslover implements HandlerExceptionResolver {
	//注入looger对象
	private static final Logger looger=LoggerFactory.getLogger(GlobalExceptionReslover.class);
	
			
    public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		//打印控制台
		ex.printStackTrace();
		//写日志
		looger.error("系统发生异常");
		looger.error("系统发生异常", ex);
		//显示错误页面
		ModelAndView mv=new ModelAndView();
		mv.setViewName("error/exception");
		return null;
	}

}
